package com.unbox.common.configuration.message;
import com.unbox.common.util.UnBoxUtils;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

public class UnBoxMessageUtils {

    private  MessageSource messageSource;

    public UnBoxMessageUtils(MessageSource messageSource) {
        this.messageSource = messageSource;
        UnBoxUtils.setUnBoxMessageUtils(this);
    }

    /**
     * 获取单个国际化翻译值
     */
    public String get(String msgKey) {
        try {
            return messageSource.getMessage(msgKey, null, LocaleContextHolder.getLocale());
        } catch (Exception e) {
            return msgKey;
        }
    }
}
